<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  <head>
    <title>Installing Kawa programs as CGI scripts</title>
    <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
    <link rel="stylesheet" type="text/css" href="kawa.css"/>
    <script src="kawa-ebook.js" type="text/javascript"/>
    <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
    <link rel="prev" href="Servlets.xhtml" title="Installing web page scripts as Servlets"/>
    <link rel="next" href="HTTP-requests.xhtml" title="Functions for accessing HTTP requests"/>
  </head>
  <body>
    <header/>
    <section class="sect1" title="Installing Kawa programs as CGI scripts" epub:type="subchapter" id="CGI-scripts">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both">Installing Kawa programs as CGI scripts</h2>
          </div>
        </div>
      </div>
      <p>The recommended way to have a web-server run a Kawa program
as a CGI script is to compile the Kawa program to a servlet
(as explained in <a class="link" href="Server-side-scripts.xhtml" title="Web page scripts">Server-side scripts</a>, and then use
Kawa’s supplied CGI-to-servlet bridge.
</p>
      <p>First, compile your program to one or more class files
as explained in <a class="link" href="Server-side-scripts.xhtml" title="Web page scripts">Server-side scripts</a>.  For example:
</p>
      <pre class="screen">kawa --servlet --xquery -C hello.xql
</pre>
      <p>Then copy the resulting <code class="literal">.class</code> files to your server’s
CGI directory.  On Red Hat GNU/Linux, you can do the following (as root):
</p>
      <pre class="screen">cp hello*.class /var/www/cgi-bin/
</pre>
      <p>Next find the <code class="literal">cgi-servlet</code> program that Kawa builds and installs.
If you installed Kawa in the default place, it will be in
<code class="literal">/usr/local/bin/cgi-servlet</code>.
(You’ll have this if you installed Kawa from source, but not
if you’re just using Kawa <code class="literal">.jar</code> file.)
Copy this program into the same CGI directory:
</p>
      <pre class="screen">cp /usr/local/bin/cgi-servlet /var/www/cgi-bin/
</pre>
      <p>You can link instead of copying:
</p>
      <pre class="screen">ln -s /usr/local/bin/cgi-servlet /var/www/cgi-bin/
</pre>
      <p>However, because of security issues this may not work, so it is
safer to copy the file.  However, if you already have a copy
of <code class="literal">cgi-servlet</code> in the CGI-directory, it is safe to make
a hard link instead of making an extra copy.
</p>
      <p>Make sure the files have the correct permissions:
</p>
      <pre class="screen">chmod a+r /var/www/cgi-bin/hello*.class /var/www/cgi-bin/hello
chmod a+x /var/www/cgi-bin/hello
</pre>
      <p>Now you should be able to run the Kawa program,
using the URL <a class="ulink" href="http://localhost/cgi-bin/hello" target="_top">http://localhost/cgi-bin/hello</a>.
It may take a few seconds to get the reply, mainly because of the
start-up time of the Java VM.  That is why servlets are
preferred.  Using the CGI interface can still be useful
for testing or when you can’t run servlets.
</p>
    </section>
    <footer>
      <div class="navfooter">
        <p>
          Up: <a accesskey="u" href="XML-tools.xhtml">Working with XML and HTML</a></p>
        <p>
        Previous: <a accesskey="p" href="Servlets.xhtml">Installing web page scripts as Servlets</a></p>
        <p>
        Next: <a accesskey="n" href="HTTP-requests.xhtml">Functions for accessing HTTP requests</a></p>
      </div>
    </footer>
  </body>
</html>
